#import "EaseWeiXinMessageCell.h"
@implementation EaseWeiXinMessageCell
+ (void)initialize
{
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.accessibilityIdentifier = @"table_cell1";
        [self _setupSubviews];
    }
    return self;
}
- (void)_setupSubviews
{
    self.backgroundColor = m1_bg_color;
    _label = [[UILabel alloc] initWithFrame:CGRectZero];
    _label.numberOfLines = 1;
    _label.font = m1_font(14);;
    self.label.textColor = [UIColor m1_colorHex:0x333333];
    [self addSubview:_label];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"msg-icon-fzwx"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"msg-icon-fzwx"] forState:UIControlStateHighlighted];
    [btn addTarget:self action:@selector(copyWeiXin) forControlEvents:UIControlEventTouchUpInside];
    [self insertSubview:btn belowSubview:self.label];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.label.mas_centerY);
        make.left.equalTo(self.label.mas_right).offset(-15);
        make.size.mas_offset(CGSizeMake(65, 44));
    }];
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 3;
    [self insertSubview:view belowSubview:self.label];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.label.mas_left).offset(-5);
        make.centerY.equalTo(self.label.mas_centerY);
        make.height.equalTo(self.label.mas_height).offset(8.3);
        make.right.equalTo(btn.mas_left).offset(13);
    }];
}
-(void)copyWeiXin{
    NSString *weiXin = self.model.text;
    if (self.model.isSender) {
        weiXin = [self.model.message.ext m1_stringKey:@"hx_attr_show_other_wx_account"];
    }else{
        weiXin = [self.model.message.ext m1_stringKey:@"hx_attr_show_my_wx_account"];
    }
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = weiXin;
    [M1Alert m1_alertWithTitle:nil message:@"已复制到粘贴板"];
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat padding = 20;
     CGSize size = [self.label sizeThatFits:CGSizeMake(SCREENWIDTH - 2 * padding, CGFLOAT_MAX)];
    self.label.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, size.width, size.height);
    if (self.label.frame.size.width >  SCREENWIDTH-90) {
        self.label.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, SCREENWIDTH-90, self.label.frame.size.height);
    }
    self.label.center = CGPointMake(SCREENWIDTH * .5f-20, 25);
}
-(void)setModel:(id<IMessageModel>)model{
    _model = model;
    NSString *text ;
    if (model.isSender) {
        text = model.text;
    }else{
        NSString *m1_name = [model.message.ext m1_stringKey:@"nick_name"];
        if (m1_name.length >6) {
            m1_name = [NSString stringWithFormat:@"%@...",[m1_name substringWithRange:NSMakeRange(0, 6)]];
        }
        text = [NSString stringWithFormat:@"%@的微信号：%@",m1_name,[model.message.ext m1_stringKey:@"hx_attr_show_my_wx_account"]];
    }
    _label.text = text;
}
- (BOOL)canBecomeFirstResponder
{
    return YES;
}
+ (NSString *)cellIdentifierWithModel:(id<IMessageModel>)model
{
    return @"EaseWeiXinMessageCell";
}
+ (CGFloat)cellHeightWithModel:(id<IMessageModel>)model
{
    return 50;
}
- (void)awakeFromNib {

    [super awakeFromNib];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];
}
@end
